package com.hyy.lotterysystem.dao.mapper;

import com.hyy.lotterysystem.dao.dataobject.ActivityDO;
import com.hyy.lotterysystem.service.enums.ActivityStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {
    @Insert("insert into activity (activity_name,description,status,duration)" +
            " values " +
            "(#{activityName},#{description},#{status},#{duration})")
    @Options(useGeneratedKeys = true,keyProperty = "id", keyColumn = "id")
    int insert(ActivityDO activityDO);


    @Select("select * from activity order by id desc limit #{offset}, #{pageSize}")
    List<ActivityDO> selectActivityList(@Param("offset") Integer offset,
                                        @Param("pageSize") Integer pageSize);


    @Select("select count(*) from activity")
    int count();

    @Select("select * from activity where id = #{id}")
    ActivityDO selectById(@Param("id") Long id);

    @Update("update activity set status = #{status} where id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);

    @Update("update activity set status =`COMPLETED` where id = #{id}")
    void activityComplete(@Param("id") Long activityId);

    /*
    * 根据活动id查看活动窗台，活动持续时间扩展用*/
    @Select("select status from activity where id=#{id}")
    ActivityStatusEnum getActivityStatus(@Param("id") Long activityId);
}
